package com.ruoyi.device.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.device.domain.SysDeviceType;
import com.ruoyi.device.service.ISysDeviceTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.device.domain.SysDeviceNew;
import com.ruoyi.device.service.ISysDeviceNewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备详细信息（NEW）Controller
 * 
 * @author zz
 * @date 2024-04-17
 */
@RestController
@RequestMapping("/device/deviceNew")
public class SysDeviceNewController extends BaseController
{
    @Autowired
    private ISysDeviceNewService sysDeviceNewService;
    @Autowired
    private ISysDeviceTypeService sysDeviceTypeService;

    /**
     * 获取全部的设备信息
     * @return
     */
    @GetMapping("/getList")
    public AjaxResult getList(){
        return success(sysDeviceTypeService.selectDeviceTypeList(new SysDeviceType()));
    }

    /**
     * 获取正常状态的所有设备
     * @return
     */
    @GetMapping("/deviceNewList")
    public AjaxResult deviceNewList(){
        SysDeviceNew sysDeviceNew = new SysDeviceNew();
        sysDeviceNew.setDeviceStatus(0);
        List<SysDeviceNew> sysDeviceNews = sysDeviceNewService.selectSysDeviceNewList(sysDeviceNew);
        return success(sysDeviceNews);
    }

    /**
     * 查询设备详细信息（NEW）列表
     */
    @PreAuthorize("@ss.hasPermi('system:deviceNew:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDeviceNew sysDeviceNew)
    {
        startPage();
        List<SysDeviceNew> list = sysDeviceNewService.selectSysDeviceNewList(sysDeviceNew);
        return getDataTable(list);
    }

    /**
     * 导出设备详细信息（NEW）列表
     */
    @PreAuthorize("@ss.hasPermi('system:deviceNew:export')")
    @Log(title = "设备详细信息（NEW）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDeviceNew sysDeviceNew)
    {
        List<SysDeviceNew> list = sysDeviceNewService.selectSysDeviceNewList(sysDeviceNew);
        ExcelUtil<SysDeviceNew> util = new ExcelUtil<SysDeviceNew>(SysDeviceNew.class);
        util.exportExcel(response, list, "设备详细信息（NEW）数据");
    }

    /**
     * 获取设备详细信息（NEW）详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:deviceNew:query')")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
    {
        return success(sysDeviceNewService.selectSysDeviceNewByDeviceId(deviceId));
    }

    /**
     * 新增设备详细信息（NEW）
     */
    @PreAuthorize("@ss.hasPermi('system:deviceNew:add')")
    @Log(title = "设备详细信息（NEW）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDeviceNew sysDeviceNew)
    {
        return toAjax(sysDeviceNewService.insertSysDeviceNew(sysDeviceNew));
    }

    /**
     * 修改设备详细信息（NEW）
     */
    @PreAuthorize("@ss.hasPermi('system:deviceNew:edit')")
    @Log(title = "设备详细信息（NEW）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDeviceNew sysDeviceNew)
    {
        return toAjax(sysDeviceNewService.updateSysDeviceNew(sysDeviceNew));
    }

    /**
     * 删除设备详细信息（NEW）
     */
    @PreAuthorize("@ss.hasPermi('system:deviceNew:remove')")
    @Log(title = "设备详细信息（NEW）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable Long[] deviceIds)
    {
        return toAjax(sysDeviceNewService.deleteSysDeviceNewByDeviceIds(deviceIds));
    }
}
